import { app } from 'electron';

const i18next = require('i18next');
const Backend = require('i18next-fs-backend');
const path = require('path');


async function InitI18n(lang: string){
    console.log("switch lang: " + lang)
    await i18next.use(Backend).init({
    lng: lang,
    fallbackLng: 'en',
    backend: {
      loadPath: path.join(app.getAppPath(), 'resources', 'language', '{{lng}}.json')
    }
  });
  console.log("i18next initialized with lang:", i18next.language);
}

function ChangeLanguage(lang: string){
    i18next.changeLanguage(lang, (err, t) => {
        if (err) return console.error('Failed to change language:', err);
        console.log(t);
      });
}

export {
    InitI18n, 
    ChangeLanguage
}
